package com.jf.pay.wx;

import java.util.SortedMap;
import java.util.TreeMap;

import com.jfinal.plugin.activerecord.Record;

/**
 * 微信支付签名工具
 * @author Administrator
 *
 */
public class WeChartPaySignUtil {
	
	/**
	 * 
	 * @param appid
	 * @param mch_id
	 * @param nonce_str
	 * @param body
	 * @param notify_url
	 * @param out_trade_no
	 * @param total_fee
	 * @param time_start
	 * @param time_expire
	 * @param trade_type
	 * @param spbill_create_ip
	 * @return
	 */
	public static SortedMap<Object,Object>  getSortedMap(String appid,String mch_id,String nonce_str,String body,
			String notify_url,String out_trade_no,int total_fee,String time_start,String time_expire,String trade_type,
			String spbill_create_ip){
		SortedMap<Object,Object> parameters = new TreeMap<Object,Object>();
		parameters.put("appid", appid);
		parameters.put("mch_id", mch_id);
		parameters.put("nonce_str", nonce_str);
		parameters.put("body", body);
		parameters.put("notify_url", notify_url);
		parameters.put("out_trade_no", out_trade_no);
		parameters.put("total_fee", total_fee);
		parameters.put("time_start", time_start);
		parameters.put("time_expire", time_expire);
		parameters.put("trade_type", trade_type);
		parameters.put("spbill_create_ip", spbill_create_ip);
		return parameters;
	}

	/**
	 * 
	 * @param appid
	 * @param mch_id
	 * @param nonce_str
	 * @param sign
	 * @param body
	 * @param out_trade_no
	 * @param
	 * @param spbill_create_ip
	 * @param time_start
	 * @param time_expire
	 * @param helpUrl
	 * @param trade_type
	 * @return
	 */
	public static Unifiedorder getUnifiedorder(String appid, String mch_id, String nonce_str, String sign, String body,
			String out_trade_no, int money, String spbill_create_ip, String time_start, String time_expire, String helpUrl,
			String trade_type) {
		Unifiedorder unifiedorder = new Unifiedorder();
		unifiedorder.setAppid(appid);
		unifiedorder.setMch_id(mch_id);
		unifiedorder.setNonce_str(nonce_str);
		unifiedorder.setSign(sign);
		unifiedorder.setBody(body);
		unifiedorder.setOut_trade_no(out_trade_no);
		unifiedorder.setTotal_fee(money);
		unifiedorder.setSpbill_create_ip(spbill_create_ip);
		unifiedorder.setTime_start(time_start);
		unifiedorder.setTime_expire(time_expire);
		unifiedorder.setNotify_url(helpUrl);
		unifiedorder.setTrade_type(trade_type);
		return unifiedorder;
	}

	/**
	 * 
	 * @param appid
	 * @param mch_id
	 * @param prepay_id
	 * @param packages
	 * @param nonce_str
	 * @param timestamp
	 * @return
	 */
	public static SortedMap<Object, Object> getSortedMap2(String appid, String mch_id, String prepay_id, String packages,
			String nonce_str, String timestamp) {
		SortedMap<Object,Object> parameters2 = new TreeMap<Object,Object>();
		parameters2.put("appid", appid);
		parameters2.put("partnerid", mch_id);
		parameters2.put("prepayid", prepay_id);
		parameters2.put("package", packages);
		parameters2.put("noncestr", nonce_str);
		parameters2.put("timestamp", timestamp);
		return parameters2;
	}

	/**
	 * 
	 * @param unifiedorderResult
	 * @param nonce_str
	 * @param timestamp
	 * @param sign2
	 * @return
	 */
	public static Record getWxRecord(UnifiedorderResult unifiedorderResult,String nonce_str,String timestamp,String sign2) {
		Record wxRecord=new Record();
		wxRecord.set("appid", unifiedorderResult.getAppid());
		wxRecord.set("partnerid", unifiedorderResult.getMch_id());
		wxRecord.set("prepayid", unifiedorderResult.getPrepay_id());
		wxRecord.set("package", "Sign=WXPay");
		wxRecord.set("noncestr", nonce_str);
		wxRecord.set("timestamp", timestamp);	
		wxRecord.set("sign", sign2);
		return wxRecord;
	}

}
